package com.worktool;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

public class WorktoolServiceImpl implements WorktoolService{

    RestTemplate restTemplate = RestExecutor.build();

    private static final String robotId = "ec6a0073c9b04e189139478c6f3f0176";

    /**
     *
     * {"code":200,"data":{"robotId":"ec6a0073c9b04e189139478c6f3f0176"},"message":"操作成功"}
     *
     * */

    @Override
    public JSONObject userInfoCreate() {
        String url = "https://worktool.asrtts.cn/robot/userInfo/create";
        JSONObject params = new JSONObject();
        params.put("name","陈东");
        params.put("phone","18871151475");
        params.put("email","domains90@163.com");
        params.put("corp","陈东");
        params.put("robotType",0);

        JSONObject result = restTemplate.postForObject(url,params,JSONObject.class);
        System.err.println(result);
        return result;
    }

    @Override
    public JSONObject sendRawMessage(JSONObject params) {
        String url = String.format("https://worktool.asrtts.cn/wework/sendRawMessage?robotId=%s",robotId);



        JSONObject result = restTemplate.postForObject(url,params,JSONObject.class);
        System.err.println(result);
        return result;
    }

    @Override
    public JSONObject callBackAdd() {
        String url = String.format("https://worktool.asrtts.cn/robot/robotInfo/callBack/add?robotId=%s",robotId);
        JSONArray callArr = new JSONArray();
        JSONObject callBack = new JSONObject();
        callBack.put("type",1);
        callBack.put("callBackUrl","http://tmp.s.weshaketv.com/lizhao/workTool/thirdQa2");
        callArr.add(callBack);

        JSONObject params = new JSONObject();
        params.put("callBack",callArr);

        System.err.println(params);
        JSONObject result = restTemplate.postForObject(url,params,JSONObject.class);
        System.err.println(result);
        return result;
    }

    /**
     * 发送文本消息
     * */
    private JSONObject sendRawMessageText(){
        JSONObject params = new JSONObject();
        params.put("socketType",2);

        JSONArray listArr = new JSONArray();
        JSONObject list = new JSONObject();
        list.put("type",203);
        list.put("titleList", Arrays.asList("下游群20230809"));
        list.put("receivedContent","hello 啊  李召");
        list.put("atList",Arrays.asList("李召"));
        listArr.add(list);
        params.put("list",listArr);
        return this.sendRawMessage(params);
    }


    /**
     * 发送图片/音视频/文件
     * */
    private JSONObject sendRawMessagefile(){
        JSONObject params = new JSONObject();
        params.put("socketType",2);

        JSONArray listArr = new JSONArray();
        JSONObject list = new JSONObject();
        list.put("type",218);
        list.put("titleList", Arrays.asList("上下游群20230809"));
        list.put("objectName","logo.png");
        list.put("fileUrl","https://cdn.asrtts.cn/static/image/logo3_180_raw.png");
        list.put("fileType","image");
        list.put("extraText","这是一个附加留言");

        listArr.add(list);
        params.put("list",listArr);
        return this.sendRawMessage(params);
    }

    /**
     * 配置指令回调地址
     * */
    private JSONObject callBackGet(){
        String url = String.format("https://worktool.asrtts.cn/robot/robotInfo/callBack/get?robotId=%s",robotId);
        JSONObject result = restTemplate.getForObject(url,JSONObject.class);
        System.err.println(result);
        return result;
    }

    /**
     * 配置QA回调地址
     *
     * */
    private JSONObject QaUpdate(){
        String url = String.format("https://worktool.asrtts.cn/robot/robotInfo/update?robotId=%s",robotId);
        JSONObject params = new JSONObject();
        params.put("openCallback",1);
        params.put("callbackUrl","http://tmp.s.weshaketv.com/lizhao/workTool/qa");
        JSONObject result = restTemplate.postForObject(url,params,JSONObject.class);
        System.err.println(result);
        return result;
    }




    public static void main(String[] args) {
        WorktoolServiceImpl worktoolService = new WorktoolServiceImpl();
        worktoolService.QaUpdate();
    }


}
